package com.hopu.bean.era;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Top10Bean implements Serializable, Comparable<Top10Bean>{

    private String era;
    private String type;
    private String sid;
    private String sname;
    private int viewCount;
    private int cartCount;
    private int parchaseCount;
    private int totalCount;

    public Top10Bean(String era, String type, String sid, String sname) {
        this.era = era;
        this.type = type;
        this.sid = sid;
        this.sname = sname;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Top10Bean top10Bean = (Top10Bean) o;
        return Objects.equals(era, top10Bean.era) &&
                Objects.equals(sid, top10Bean.sid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(era, sid);
    }


    @Override
    public int compareTo(Top10Bean o) {
        if (o.getParchaseCount() == this.getParchaseCount()) {
            if (o.getCartCount() == this.getCartCount()) {
                return o.getViewCount() - this.getViewCount();
            } else {
                return o.getCartCount() - this.getCartCount();
            }
        } else {
            return o.getParchaseCount() - this.getParchaseCount();
        }
    }
}
